package com.bishe.demo.modules.tourism.dao;

import com.bishe.demo.modules.tourism.entity.Route;
import com.bishe.demo.modules.tourism.entity.RouteOrder;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Description RouteOrder
 * @Author Lubb
 * @Date 2021/4/9 9:52
 */
@Repository
@Mapper
public interface RouteOrderDao {
    @Insert("insert into tourism_order(fk_route_id,fk_user_id,ordering_ime,status,comment) values(#{fkRouteId},#{fkUserId},#{orderingTime},0,0)")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    void addRouteOrder(RouteOrder routeOrder);

    @Delete("delete from tourism_order where id = #{id}")
    void deleteRouteOrderById(Integer id);

    @Update("update tourism_order set comment = #{comment} where id = #{id}")
    void updateRouteOrderComment(RouteOrder routeOrder);

    @Select("select * from tourism_order where fk_user_id = #{userId}")
    @Results(id = "baseResult",value = {
            @Result(column = "fk_route_id",property = "fkRouteId"),
            @Result(column = "fk_route_id",property = "route",javaType = Route.class,
                    one = @One(select = "com.bishe.demo.modules.tourism.dao.RouteDao.getRouteById"))
    })
    List<RouteOrder> getRouteOrderByUserId(Integer userId);

    @Select("select * from tourism_order where id = #{id}")
    RouteOrder getRouteOrderById(Integer id);
}
